#include <iostream>
#include <memory>
using namespace std;
void shared() {
  shared_ptr<int> sp1 = make_shared<int>();
  // init: count 0->1
  cout << sp1.use_count() << endl;
  {
    shared_ptr<int> sp2 = sp1;
    // copy: count 1->2
    cout << sp1.use_count() << endl;
    // delete p2: count 2->1
  }
  cout << sp1.use_count() << endl;
}
void unique() {
  unique_ptr<int> up = make_unique<int>(1);
  // shared_ptr<int> sp = up;
  // unique_ptr<int> up2 = up;
  // weak_ptr<int> wp = up;
}
void weak() {
  weak_ptr<int> wp;
  {
    shared_ptr<int> sp = make_shared<int>(2);
    wp = sp;
    if (auto p = wp.lock(); p) {
      cout << *p << endl;
    } else {
      cout << "expired" << endl;
    }
  }
  if (auto p = wp.lock(); p) {
    cout << *p << endl;
  } else {
    cout << "expired" << endl;
  }
}
int main() {
  shared();
  weak();
}